from PyQt5 import QtCore, QtGui, QtWidgets
from lanzou.gui.others import MyLineEdit, MyTableView
from lanzou.debug import SRC_DIR


class Ui_MainWindow(QtWidgets.QMainWindow):
    def __init__(self):
        super(Ui_MainWindow, self).__init__()

    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.setEnabled(True)
        MainWindow.resize(1000, 650)
        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")
        self.verticalLayout = QtWidgets.QVBoxLayout(self.centralwidget)
        self.verticalLayout.setObjectName("verticalLayout")
        self.tabWidget = QtWidgets.QTabWidget(self.centralwidget)
        self.tabWidget.setObjectName("tabWidget")
        self.share_tab = QtWidgets.QWidget()
        self.share_tab.setObjectName("share_tab")
        self.share_vlayout = QtWidgets.QVBoxLayout(self.share_tab)
        self.share_vlayout.setObjectName("share_vlayout")
        self.share_hlayout_top = QtWidgets.QHBoxLayout()
        self.share_hlayout_top.setObjectName("share_hlayout_top")
        self.label_share_url = QtWidgets.QLabel(self.share_tab)
        self.label_share_url.setObjectName("label_share_url")
        self.share_hlayout_top.addWidget(self.label_share_url)
        self.line_share_url = QtWidgets.QLineEdit(self.share_tab)
        self.line_share_url.setObjectName("line_share_url")
        self.line_share_pwd = QtWidgets.QLineEdit(self.share_tab)
        self.line_share_pwd.setObjectName("line_share_pwd")
        self.share_hlayout_top.addWidget(self.line_share_url)
        self.share_hlayout_top.addWidget(self.line_share_pwd)
        self.btn_extract = QtWidgets.QPushButton(self.share_tab)
        self.btn_extract.setObjectName("btn_extract")
        self.share_hlayout_top.addWidget(self.btn_extract)
        self.share_vlayout.addLayout(self.share_hlayout_top)
        self.table_share = QtWidgets.QTableView(self.share_tab)
        self.table_share.setObjectName("table_share")
        self.share_vlayout.addWidget(self.table_share)
        self.share_hlayout_bottom = QtWidgets.QHBoxLayout()
        self.share_hlayout_bottom.setObjectName("share_hlayout_bottom")
        self.btn_share_select_all = QtWidgets.QPushButton(self.share_tab)
        self.btn_share_select_all.setObjectName("btn_share_select_all")
        self.share_hlayout_bottom.addWidget(self.btn_share_select_all)
        self.label_dl_path = QtWidgets.QLabel(self.share_tab)
        self.label_dl_path.setObjectName("label_dl_path")
        self.share_hlayout_bottom.addWidget(self.label_dl_path)
        self.share_set_dl_path = MyLineEdit(self.share_tab)
        self.share_set_dl_path.setObjectName("share_set_dl_path")
        self.share_hlayout_bottom.addWidget(self.share_set_dl_path)
        self.btn_share_dl = QtWidgets.QPushButton(self.share_tab)
        self.btn_share_dl.setObjectName("btn_share_dl")
        self.share_hlayout_bottom.addWidget(self.btn_share_dl)
        self.share_vlayout.addLayout(self.share_hlayout_bottom)
        self.tabWidget.addTab(self.share_tab, "")
        self.disk_tab = QtWidgets.QWidget()
        self.disk_tab.setEnabled(True)
        self.disk_tab.setMinimumSize(QtCore.QSize(620, 0))
        self.disk_tab.setObjectName("disk_tab")
        self.disk_vlayout = QtWidgets.QVBoxLayout(self.disk_tab)
        self.disk_vlayout.setObjectName("disk_vlayout")
        self.disk_hlayout_top = QtWidgets.QHBoxLayout()
        self.disk_hlayout_top.setObjectName("disk_hlayout_top")
        self.disk_loc_hbox = QtWidgets.QHBoxLayout()
        self.disk_loc_hbox.setObjectName("disk_loc_hbox")
        self.label_disk_loc = QtWidgets.QLabel(self.disk_tab)
        self.label_disk_loc.setObjectName("label_disk_loc")
        self.disk_loc_hbox.addWidget(self.label_disk_loc)
        self.disk_hlayout_top.addLayout(self.disk_loc_hbox)
        spacerItem = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
        self.disk_hlayout_top.addItem(spacerItem)
        self.btn_disk_mkdir = QtWidgets.QPushButton(self.disk_tab)
        self.btn_disk_mkdir.setObjectName("btn_disk_mkdir")
        self.disk_hlayout_top.addWidget(self.btn_disk_mkdir)
        self.disk_vlayout.addLayout(self.disk_hlayout_top)
        self.table_disk = MyTableView(self.disk_tab)
        self.table_disk.setObjectName("table_disk")
        self.disk_vlayout.addWidget(self.table_disk)
        self.disk_hlayout_bottom = QtWidgets.QHBoxLayout()
        self.disk_hlayout_bottom.setObjectName("disk_hlayout_bottom")
        self.btn_disk_select_all = QtWidgets.QPushButton(self.disk_tab)
        self.btn_disk_select_all.setObjectName("btn_disk_select_all")
        self.disk_hlayout_bottom.addWidget(self.btn_disk_select_all)
        spacerItem1 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
        self.disk_hlayout_bottom.addItem(spacerItem1)
        self.btn_disk_delete = QtWidgets.QPushButton(self.disk_tab)
        self.btn_disk_delete.setObjectName("btn_disk_delete")
        self.disk_hlayout_bottom.addWidget(self.btn_disk_delete)
        self.btn_disk_dl = QtWidgets.QPushButton(self.disk_tab)
        self.btn_disk_dl.setObjectName("btn_disk_dl")
        self.disk_hlayout_bottom.addWidget(self.btn_disk_dl)
        self.disk_vlayout.addLayout(self.disk_hlayout_bottom)
        self.tabWidget.addTab(self.disk_tab, "")

        self.rec_tab = QtWidgets.QWidget()
        self.rec_tab.setObjectName("rec_tab")
        self.rec_verticalLayout = QtWidgets.QVBoxLayout(self.rec_tab)
        self.rec_verticalLayout.setObjectName("rec_verticalLayout")
        self.rec_horizontalLayout = QtWidgets.QHBoxLayout()
        self.rec_horizontalLayout.setObjectName("rec_horizontalLayout")
        self.btn_rec_select_all = QtWidgets.QPushButton(self.rec_tab)
        self.btn_rec_select_all.setObjectName("btn_rec_select_all")
        self.rec_horizontalLayout.addWidget(self.btn_rec_select_all)
        self.btn_recovery = QtWidgets.QPushButton(self.rec_tab)
        self.btn_recovery.setObjectName("btn_recovery")
        self.rec_horizontalLayout.addWidget(self.btn_recovery)
        self.btn_rec_delete = QtWidgets.QPushButton(self.rec_tab)
        self.btn_rec_delete.setObjectName("btn_rec_delete")
        self.rec_horizontalLayout.addWidget(self.btn_rec_delete)
        self.rec_horizontalLayout.addStretch(1)
        self.btn_rec_clean = QtWidgets.QPushButton(self.rec_tab)
        self.btn_rec_clean.setObjectName("btn_rec_clean")
        self.rec_horizontalLayout.addWidget(self.btn_rec_clean)
        self.btn_recovery_all = QtWidgets.QPushButton(self.rec_tab)
        self.btn_recovery_all.setObjectName("btn_recovery_all")
        self.rec_horizontalLayout.addWidget(self.btn_recovery_all)
        self.btn_rec_expire_files = QtWidgets.QPushButton(self.rec_tab)
        self.btn_rec_expire_files.setObjectName("btn_rec_expire_files")
        self.rec_horizontalLayout.addWidget(self.btn_rec_expire_files)
        self.rec_verticalLayout.addLayout(self.rec_horizontalLayout)
        self.table_rec = QtWidgets.QTableView(self.rec_tab)
        self.table_rec.setObjectName("table_rec")
        self.rec_verticalLayout.addWidget(self.table_rec)
        self.tabWidget.addTab(self.rec_tab, "")

        self.jobs_tab = QtWidgets.QWidget()
        self.jobs_tab.setObjectName("jobs_tab")
        self.jobs_verticalLayout = QtWidgets.QVBoxLayout(self.jobs_tab)
        self.jobs_verticalLayout.setObjectName("jobs_verticalLayout")
        self.jobs_horizontalLayout = QtWidgets.QHBoxLayout()
        self.jobs_horizontalLayout.setObjectName("jobs_horizontalLayout")
        self.btn_jobs_start_all = QtWidgets.QPushButton(self.jobs_tab)
        self.btn_jobs_clean_all = QtWidgets.QPushButton(self.jobs_tab)
        self.jobs_horizontalLayout.addWidget(self.btn_jobs_start_all)
        self.jobs_horizontalLayout.addStretch(1)
        self.jobs_horizontalLayout.addWidget(self.btn_jobs_clean_all)
        self.table_jobs = MyTableView(self.jobs_tab)
        self.table_jobs.setObjectName("table_jobs")
        self.jobs_verticalLayout.addLayout(self.jobs_horizontalLayout)
        self.jobs_verticalLayout.addWidget(self.table_jobs)
        self.tabWidget.addTab(self.jobs_tab, "")

        self.verticalLayout.addWidget(self.tabWidget)
        MainWindow.setCentralWidget(self.centralwidget)
        self.menubar = QtWidgets.QMenuBar(MainWindow)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 640, 30))
        self.menubar.setObjectName("menubar")
        self.acount = QtWidgets.QMenu(self.menubar)
        self.acount.setObjectName("acount")
        self.files = QtWidgets.QMenu(self.menubar)
        self.files.setObjectName("files")
        self.help = QtWidgets.QMenu(self.menubar)
        self.help.setObjectName("help")
        MainWindow.setMenuBar(self.menubar)
        self.statusbar = QtWidgets.QStatusBar(MainWindow)
        self.statusbar.setObjectName("statusbar")
        MainWindow.setStatusBar(self.statusbar)
        self.toolbar = QtWidgets.QToolBar(MainWindow)
        self.toolbar.setObjectName("toolbar")
        MainWindow.addToolBar(QtCore.Qt.TopToolBarArea, self.toolbar)
        self.login = QtWidgets.QAction(MainWindow)
        self.login.setObjectName("login")
        self.logout = QtWidgets.QAction(MainWindow)
        self.logout.setObjectName("logout")
        self.upload = QtWidgets.QAction(MainWindow)
        self.upload.setObjectName("upload")
        self.download = QtWidgets.QAction(MainWindow)
        self.download.setObjectName("download")
        self.delete = QtWidgets.QAction(MainWindow)
        self.delete.setObjectName("delete")
        self.show_toolbar = QtWidgets.QAction(MainWindow)
        self.show_toolbar.setObjectName("show_toolbar")
        self.merge_file = QtWidgets.QAction(MainWindow)
        self.merge_file.setObjectName("merge_file")
        self.setting_menu = QtWidgets.QAction(MainWindow)
        self.setting_menu.setObjectName("setting_menu")
        self.how = QtWidgets.QAction(MainWindow)
        self.how.setObjectName("how")
        self.about = QtWidgets.QAction(MainWindow)
        self.about.setObjectName("about")
        self.acount.addSeparator()
        self.acount.addAction(self.login)
        self.acount.addAction(self.logout)
        self.files.addAction(self.upload)
        self.files.addAction(self.download)
        self.files.addAction(self.delete)
        self.files.addAction(self.show_toolbar)
        self.files.addAction(self.merge_file)
        self.files.addAction(self.setting_menu)
        self.help.addAction(self.how)
        self.help.addAction(self.about)
        self.menubar.addAction(self.acount.menuAction())
        self.menubar.addAction(self.files.menuAction())
        self.menubar.addAction(self.help.menuAction())
        # 工具栏
        self.toolbar.addAction(self.login)
        # 状态栏
        self.statusbar_msg_label = QtWidgets.QLabel()
        self.statusbar_load_lb = QtWidgets.QLabel()
        self.statusbar_load_movie = QtGui.QMovie(SRC_DIR + "loading_more.gif")
        self.statusbar_load_lb.setMovie(self.statusbar_load_movie)
        self.statusbar_msg_label.setObjectName("msg_label")
        self.statusbar_load_lb.setObjectName("msg_movie_lb")
        self.statusbar.addWidget(self.statusbar_load_lb)
        self.statusbar.addWidget(self.statusbar_msg_label)

        self.retranslateUi(MainWindow)
        self.other_init()
        self.set_window_at_center()
        self.create_left_menus()
        self.init_main_menu()
        self.text_add_shadow()
        QtCore.QMetaObject.connectSlotsByName(MainWindow)

    def retranslateUi(self, MainWindow):
        _translate = QtCore.QCoreApplication.translate
        MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
        self.label_share_url.setText(_translate("MainWindow", "蓝奏链接"))
        self.btn_extract.setText(_translate("MainWindow", "提取"))
        self.btn_share_select_all.setText(_translate("MainWindow", "全选"))
        self.label_dl_path.setText(_translate("MainWindow", "文件下载路径"))
        self.btn_share_dl.setText(_translate("MainWindow", "下载选中文件"))
        self.tabWidget.setTabText(self.tabWidget.indexOf(self.share_tab), _translate("MainWindow", "蓝奏云链接提取"))
        self.label_disk_loc.setText(_translate("MainWindow", "位置"))
        self.btn_disk_mkdir.setText(_translate("MainWindow", "新建文件夹"))
        self.btn_disk_select_all.setText(_translate("MainWindow", "全选"))
        self.btn_disk_delete.setText(_translate("MainWindow", "删除"))
        self.btn_disk_dl.setText(_translate("MainWindow", "下载"))
        self.tabWidget.setTabText(self.tabWidget.indexOf(self.disk_tab), _translate("MainWindow", "我的蓝奏云"))
        self.btn_rec_select_all.setText(_translate("MainWindow", "全选"))
        self.btn_recovery.setText(_translate("MainWindow", "还原"))
        self.btn_rec_delete.setText(_translate("MainWindow", "彻底删除"))
        self.btn_rec_clean.setText(_translate("MainWindow", "清空回收站"))
        self.btn_recovery_all.setText(_translate("MainWindow", "全部还原"))
        self.btn_rec_expire_files.setText(_translate("MainWindow", "过期文件"))
        self.tabWidget.setTabText(self.tabWidget.indexOf(self.rec_tab), _translate("MainWindow", "回收站"))
        self.btn_jobs_start_all.setText(_translate("MainWindow", "开始所有暂停任务"))
        self.btn_jobs_clean_all.setText(_translate("MainWindow", "删除已完成任务"))
        self.tabWidget.setTabText(self.tabWidget.indexOf(self.jobs_tab), _translate("MainWindow", "任务管理"))
        self.acount.setTitle(_translate("MainWindow", "登录"))
        self.files.setTitle(_translate("MainWindow", "文件"))
        self.help.setTitle(_translate("MainWindow", "帮助"))
        self.toolbar.setWindowTitle(_translate("MainWindow", "工具栏"))
        self.login.setText(_translate("MainWindow", "登录"))
        self.logout.setText(_translate("MainWindow", "登出"))
        self.upload.setText(_translate("MainWindow", "上传"))
        self.download.setText(_translate("MainWindow", "下载"))
        self.delete.setText(_translate("MainWindow", "删除"))
        self.show_toolbar.setText(_translate("MainWindow", "显示工具栏"))
        self.merge_file.setText(_translate("MainWindow", "合并文件"))
        self.setting_menu.setText(_translate("MainWindow", "设置"))
        self.how.setText(_translate("MainWindow", "使用说明"))
        self.about.setText(_translate("MainWindow", "关于"))

    def other_init(self):
        # 设置 tab
        self.tabWidget.setCurrentIndex(0)
        self.tabWidget.removeTab(3)
        self.tabWidget.removeTab(2)
        self.tabWidget.removeTab(1)
        self.disk_tab.setEnabled(False)
        self.rec_tab.setEnabled(False)
        self.jobs_tab.setEnabled(False)

    def set_window_at_center(self):
        screen = QtWidgets.QDesktopWidget().screenGeometry()
        size = self.geometry()
        new_left = int((screen.width() - size.width()) / 2)
        new_top = int((screen.height() - size.height()) / 2)
        self.move(new_left, new_top)

    def create_left_menus(self):
        self.left_menus = QtWidgets.QMenu()
        self.left_menu_share_url = self.left_menus.addAction("外链分享地址等")
        self.left_menu_share_url.setIcon(QtGui.QIcon(SRC_DIR + "share.ico"))
        self.left_menu_rename_set_desc = self.left_menus.addAction("修改文件描述（支持批量）")
        self.left_menu_rename_set_desc.setIcon(QtGui.QIcon(SRC_DIR + "desc.ico"))
        self.left_menu_set_pwd = self.left_menus.addAction("设置提取码（支持批量）")
        self.left_menu_set_pwd.setIcon(QtGui.QIcon(SRC_DIR + "password.ico"))
        self.left_menu_move = self.left_menus.addAction("移动（支持批量）")
        self.left_menu_move.setIcon(QtGui.QIcon(SRC_DIR + "move.ico"))
        self.left_menu_copy = self.left_menus.addAction("复制分享链接")
        self.left_menu_copy.setIcon(QtGui.QIcon(SRC_DIR + "count.ico"))

    def init_main_menu(self):
        self.login.setIcon(QtGui.QIcon(SRC_DIR + "login.ico"))
        self.login.setShortcut("Ctrl+L")
        self.logout.setIcon(QtGui.QIcon(SRC_DIR + "logout.ico"))
        self.logout.setShortcut("Ctrl+Q")    # 登出快捷键
        self.logout.setEnabled(False)  # 初始状态
        self.download.setIcon(QtGui.QIcon(SRC_DIR + "download.ico"))
        self.download.setShortcut("Ctrl+J")
        self.download.setEnabled(False)  # 初始状态
        self.delete.setIcon(QtGui.QIcon(SRC_DIR + "delete.ico"))
        self.delete.setShortcut("Ctrl+D")
        self.delete.setEnabled(False)  # 初始状态
        self.show_toolbar.setIcon(QtGui.QIcon(SRC_DIR + "password.ico"))
        self.show_toolbar.setShortcut("Ctrl+T")
        self.toolbar.close()  # 工具栏初始状态
        self.merge_file.setIcon(QtGui.QIcon(SRC_DIR + "folder.gif"))
        self.merge_file.setShortcut("Ctrl+M")
        self.setting_menu.setIcon(QtGui.QIcon(SRC_DIR + "settings.ico"))
        self.setting_menu.setShortcut("Ctrl+P")
        self.how.setIcon(QtGui.QIcon(SRC_DIR + "help.ico"))
        self.how.setShortcut("F1")
        self.about.setIcon(QtGui.QIcon(SRC_DIR + "about.ico"))
        self.about.setShortcut("Ctrl+B")
        self.upload.setIcon(QtGui.QIcon(SRC_DIR + "upload.ico"))
        self.upload.setShortcut("Ctrl+U")  # 上传快捷键
        self.upload.setEnabled(False)  # 初始状态

    def text_add_shadow(self):
        share_url_shadow = QtWidgets.QGraphicsDropShadowEffect()
        share_url_shadow.setBlurRadius(4)
        share_url_shadow.setColor(QtGui.QColor('red'))
        share_url_shadow.setOffset(0)
        self.label_share_url.setGraphicsEffect(share_url_shadow)

        dl_path_shadow = QtWidgets.QGraphicsDropShadowEffect()
        dl_path_shadow.setBlurRadius(4)
        dl_path_shadow.setColor(QtGui.QColor('green'))
        dl_path_shadow.setOffset(0)
        self.label_dl_path.setGraphicsEffect(dl_path_shadow)

        disk_loc_shadow = QtWidgets.QGraphicsDropShadowEffect()
        disk_loc_shadow.setBlurRadius(5)
        disk_loc_shadow.setColor(QtGui.QColor('white'))
        disk_loc_shadow.setOffset(0)
        self.label_disk_loc.setGraphicsEffect(disk_loc_shadow)
